# coding=utf-8

from django.http import HttpResponse
from django.shortcuts import render_to_response
from decorators import login_required

import json

def index(request):
	return render_to_response('index.tpl')

@login_required(cmd='cmd',exceptions=['login'])
def cmd(request):
	cmd = request.REQUEST.get('cmd','');
	if not cmd:
		return HttpResponse(json.dumps({'code':-1,
			'html':'<span class="error">请输入命令</span>'}));
	return HttpResponse(json.dumps({'code':0,'html':'<div id="login"></div>','script':'''
		$('#login').dialog({
			autoOpen: true,
			modal:true
		});
		$('#login').bind('dialogclose',function(){
			$(this).dialog('destroy');
			$('.valin').select();
			$(this).remove();
		});
		$('#mud')[0].connect('127.0.0.1',8001);
	'''}))
